package com.github.aloxc.plugin.restplus.action;


import com.github.aloxc.plugin.restplus.i18n.I18Bundle;
import com.github.aloxc.plugin.restplus.common.PsiClassHelper;
import com.github.aloxc.plugin.DonotGuard;
import com.github.aloxc.plugin.restplus.popup.PopupBalloon;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;

import java.awt.datatransfer.StringSelection;
/**
 *
 * @author leero
 */
@DonotGuard
public class ConvertClassToJsonCompressedAction extends ConvertClassToJsonAction {
    @Override
    public void actionPerformed(AnActionEvent e) {
        Editor myEditor = e.getData(CommonDataKeys.EDITOR);
        PsiElement psiElement = e.getData(CommonDataKeys.PSI_ELEMENT);
        PsiClass psiClass = getPsiClass(psiElement);

        if(psiClass == null) {
            return;
        }

        String json = PsiClassHelper.create(psiClass).convertClassToJson(myProject(e), false);
        CopyPasteManager.getInstance().setContents(new StringSelection(json));
        PopupBalloon.showPopupBalloon(myEditor,String.format(I18Bundle.getMessage("com.github.aloxc.plugin.restplus.copy.beanjsonCompressed.text"),json),false);
    }

    @Override
    public boolean isCompressed() {
        return true;
    }
}
